package com.tj.template.application.user.input;

import com.fqgj.common.api.ParamsObject;
import com.fqgj.common.utils.StringUtils;
import com.tj.bo.common.conf.enums.LoginTypeEnum;
import com.tj.bo.common.conf.util.ParamsValidateUtil;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * User: binary
 * Date: 2020/6/9
 * Time: 下午5:12
 */
public class UserPasswordLoginApInput extends ParamsObject {
    private String email;

    private String password;

    private Integer type;

    public Integer getType() {
        return type;
    }

    public UserPasswordLoginApInput setType(Integer type) {
        this.type = type;
        return this;
    }

    public String getEmail() {
        return email;
    }

    public UserPasswordLoginApInput setEmail(String email) {
        this.email = email;
        return this;
    }

    public String getPassword() {
        return password;
    }

    public UserPasswordLoginApInput setPassword(String password) {
        this.password = password;
        return this;
    }

    @Override
    public void validate() {

        ParamsValidateUtil.checkParams(StringUtils.isEmpty(password), "password can not be empty");
        if(type == null){
            ParamsValidateUtil.checkParams(StringUtils.isEmpty(email), "email can not be empty");
        }else{
            ParamsValidateUtil.checkParams(LoginTypeEnum.getByCode(type) == null, "type is invalid");
            if(Objects.equals(LoginTypeEnum.getByCode(type), LoginTypeEnum.MOBILE)){
                ParamsValidateUtil.checkParams(StringUtils.isEmpty(email), "phone number can not be empty");
            }else{
                ParamsValidateUtil.checkParams(StringUtils.isEmpty(email), "email can not be empty");
            }
        }
    }
}
